DAY12:Complementary DNA


Posted by birdbirdmurmur on 2023-07-25

題目連結:

Complementary DNA

解法:

function DNAStrand(dna){
  return dna.replace(/[ACTG]/g, match =>{
    switch(match){
      case "A":
        return "T";
      case "T":
        return "A";
      case "C":
        return "G";
      case "G":
        return "C";
    }
  })
}

筆記:

替換字先想到replace()
/[ATCG]/g:找到所有A、T、C、G四個字母
switch()將傳遞進來的值通過case轉換成另外一個字


#javascript #Codewars #replace #switch







Related Posts

Selenium with JS and infinite scroll

Selenium with JS and infinite scroll

[Release Notes] 20200924_v1 - Fix blog post serie checkbox bug & add publish type modal

[Release Notes] 20200924_v1 - Fix blog post serie checkbox bug & add publish type modal

滲透測試重新打底(3.1)--論Web入侵之Burp Suite基本使用

滲透測試重新打底(3.1)--論Web入侵之Burp Suite基本使用


Comments